package org.dtc.geo.picture;

import com.google.common.collect.Lists;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author zhouyu
 * @create 2024-01-08 16:31
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PhotoMetaData {

    private String id;
    private String series;
    /**
     * Integer
     */
    private String sheet;
    private String title;
    private String edition;
    /**
     * Integer
     */
    private String variant;
    private String scale;
    private String coverage;
    /**
     * Integer
     */
    private String year;
    private String dataSurvey;
    private String author;
    private String pub;
    private String info;
    private String url;
    private String previewUrl;

    @Override
    public String toString() {
        List<String> strList = Lists.newArrayList();
        boolean flag = false;
        flag = haveContent(id) ? strList.add(replace(id)) : strList.add("");
        flag = haveContent(series) ? strList.add(replace(series)) : strList.add("");
        flag = haveContent(sheet) ? strList.add(replace(sheet)) : strList.add("");
        flag = haveContent(title) ? strList.add(replace(title)) : strList.add("");
        flag = haveContent(edition) ? strList.add(replace(edition)) : strList.add("");
        flag = haveContent(variant) ? strList.add(replace(variant)) : strList.add("");
        flag = haveContent(scale) ? strList.add(replace(scale)) : strList.add("");
        flag = haveContent(coverage) ? strList.add(replace(coverage)) : strList.add("");
        flag = haveContent(year) ? strList.add(replace(year)) : strList.add("");
        flag = haveContent(dataSurvey) ? strList.add(replace(dataSurvey)) : strList.add("");
        flag = haveContent(author) ? strList.add(replace(author)) : strList.add("");
        flag = haveContent(pub) ? strList.add(replace(pub)) : strList.add("");
        flag = haveContent(info) ? strList.add(replace(info)) : strList.add("");
        flag = haveContent(url) ? strList.add(replace(url)) : strList.add("");
        flag = haveContent(previewUrl) ? strList.add(replace(previewUrl)) : strList.add("");
        return StringUtils.joinWith("\t", strList.toArray());
    }

    public static String getHeaderInfo() {
        List<String> fieldNameList =
                Lists.newArrayList(
                        "id", "series", "sheet", "title", "edition",
                        "variant", "scale", "coverage", "year", "dataSurvey",
                        "author", "pub", "info", "url", "previewUrl"
                );
        return StringUtils.joinWith("\t", fieldNameList.toArray());
    }

    public String replace(String input) {
        if (StringUtils.isEmpty(input)) {
            return input;
        }

        return input.replace("\n", "")
                .replace("\t", "");
    }

    public boolean haveContent(String input) {
        if(StringUtils.isBlank(input)) {
            return false;
        }
        
        if(StringUtils.equals(input, "-")) {
            return false;
        }
        
        return true;
    }
}
